package com.ceuer.demo.juc.single;

/**
 * 单例模式-DCL 懒汉式
 */
public class LazyMan1 {
	private LazyMan1(){
		System.out.println(Thread.currentThread().getName()+"\t ok");
	}
	
	private static LazyMan1 LAZYMAN1;
	
	public static LazyMan1 getInstance(){
		if(LAZYMAN1==null){
			LAZYMAN1=new LazyMan1();
		}
		return LAZYMAN1;
	}
	
	/*
		此处运行结果可能会是
			Thread-0	 ok
			Thread-1	 ok
		说明并发下，会去实例化好几个对象就有问题
	 */
	public static void main(String[] args) {
		for (int i = 0; i < 10; i++) {
			new Thread(()->{
				LazyMan1.getInstance();
			}).start();
		}
	}
	
}
